<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业1</title>
</head>
<body>
    <input type="checkbox" value="">全选
    <p><input type="checkbox" name="" id="" class="q1"></p>
    <p><input type="checkbox" name="" id="" class="q1"></p>


    <script src="./one.js"></script>
    <script>
        let quan=document.querySelector('input');
        let xuanze=document.querySelectorAll('p');
        let inp=document.getElementsByClassName('q1');

        for(var i=0;i<cartGoods.length;i++){
            xuanze[i].innerHTML+=cartGoods[i].goodsname+'单价:'+cartGoods[i].price;
            inp[i].checked=cartGoods[i].isChecked;
        }
        quan.onclick=function(){
            if(this.checked==true){
                // inp[1].setAttribute('checked','checked');
                for(var i=0;i<inp.length;i++){
                    inp[i].checked=true;
                    console.log('全部选中');
                }
                
            }else{
                for(var i=0;i<inp.length;i++){
                    inp[i].checked=false;
                    console.log('未全部选中');

                }
            }
        }
        for(var n=0; n<inp.length;n++){
            inp[n].onclick=function(){
                for(var j=0;j<inp.length;j++){
                    if(inp[j].checked==true){
                        quan.checked=true;
                        console.log('全部选中');
                }else if(inp[j].checked==false){
                    quan.checked=false;
                    console.log('未全部选中');

                }
                }
               
            }
        }
    </script>
</body>
</html>